package com.lxl.commons.mapper.impl;

import com.lxl.commons.mapper.IMapper;
import com.lxl.workbench.entity.Book;
import javax.servlet.jsp.jstl.sql.Result;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 书的Result转化成List集合
 * @author 北上寻海
 */
public class BookMapperImpl implements IMapper {

    @Override
    public List<Book> mapper(Result result) throws SQLException {
        List<Book> list = new ArrayList<>();
        if(result.getRowCount()!=0){
            for (int i = 0 ;i<result.getRowCount();i++){
                Book book = new Book();
                book.setId((String)result.getRowsByIndex()[i][0]);
                book.setIsbn((String)result.getRowsByIndex()[i][1]);
                book.setBookName((String)result.getRowsByIndex()[i][2]);
                book.setTypeId((String)result.getRowsByIndex()[i][3]);
                book.setRemaining((int)result.getRowsByIndex()[i][4]);
                book.setPrice((String)result.getRowsByIndex()[i][5]);
                book.setAuthor((String) result.getRowsByIndex()[i][6]);
                list.add(book);
            }
        }
        return list;
    }
}
